var { deviceUtils, logUtils, appUtils, gUtils } = require("../utils/index");
function main(appName, span) {
  span = (span || 10) * 60;
  var startTime = Date.now();
  while (true) {
    var hasExec = gUtils.hasExec(startTime);
    if (hasExec >= span) {
      logUtils.log("已经阅读" + hasExec + "|" + span + "秒");
      return;
    }
    read(appName);
  }
}

function read(appName) {
  var span = gUtils.random(3, 5) * 60;
  var homeTimes = 0;
  var startTime = Date.now();
  while (true) {
    var hasExec = gUtils.hasExec(startTime);
    if (hasExec >= span) {
      return;
    }
    gUtils.sleep(5, 15);
    if (homeTimes < 2) {
      if (gUtils.possible(1, 20)) {
        appUtils.home(appName);
        homeTimes++;
      }
    }
  }
}

Wang.main = main;
